from lib.douyin.doudian.core.AccessTokenBuilder import AccessTokenBuilder
from lib.douyin.doudian.core.DoudianOpConfig import GlobalConfig
from lib.douyin.doudian.core.DoudianOpSpiRequest import DoudianOpSpiRequest
from lib.douyin.doudian.api.sms_send.SmsSendRequest import SmsSendRequest

# 定义自己的全局变量
GlobalConfig.appKey = "7067057640550958605"  # appKey
GlobalConfig.appSecret = "9300e292-2e0a-4b54-ba0f-98a605223fd8"  # appSecret


# ====API使用示例=====
# 获取token
token = AccessTokenBuilder.buildTokenByShopId("2614741")
# 创建Request对象，假设调用的方法名称是: demo.method
request = SmsSendRequest()
param = request.getParams()
param.sms_account = "1234"
param.sign = "火山测试"
param.template_id = "ST_60505c68"
param.template_param = "{'code': '1234'}"
param.tag = "回执"
param.post_tel = "13141313131"
param.user_ext_code = "abc"
# 发起API调用
response = request.execute(token)


# ====SPI使用示例=====
# 定义spi处理器
# def bizHandler(context):
#     # 获取服务器传入的paramJson（已经反序列化成object）
#     param = context.getParamJsonObject()
#
#     # 如果处理成功执行下面代码
#     context.wrapSuccess()
#     data = {"xxxx": "xxxx"}
#     context.setResponseData(data)
#
#     # 如果处理失败执行下面的代码
#     context.wrapError(10001, "internal error")


request = DoudianOpSpiRequest()
# 服务端调用spi接口时的链接参数
# request.init(appKey="7037989963426022956", sign="a68b72f8ccc9c43acc79b2fbbeac392555e042d0c690e5fba1dc9355c50fb548",
#              signV2="xxx", signMethod="hmac-sha256", timestamp="2022-02-10 10:59:24",
#              paramJson="{}")
# # 注册一个处理器
# request.registerHandler(bizHandler)
# 执行处理器
# response = request.execute(parseAsJsonString=True)
# 将response返回给服务器
# write return code here
